package com.zfzs.post.modules.post.rest;

import com.zfzs.post.aop.log.Log;
import com.zfzs.post.common.bean.ResponseResult;
import com.zfzs.post.modules.post.domain.TerminalInfo;
import com.zfzs.post.modules.post.service.TerminalInfoService;
import com.zfzs.post.modules.post.service.TerminalService;
import com.zfzs.post.modules.post.service.dto.TerminalInfoQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 终端管理
 *
 * @author ck
 * @date 2019-11-12
 */
@RestController
@RequestMapping("terminal")
public class TerminalController {

    @Autowired
    private TerminalInfoService postTerminalInfoService;

    @Autowired
    private TerminalService terminalService;

    /**
     * 查询终端列表
     *
     * @param criteria
     * @return
     */
    @Log("查询终端列表")
    @GetMapping(value = "/list")
    public ResponseResult getPostTerminalInfos(TerminalInfoQueryCriteria criteria, Integer page, Integer size) {
        return ResponseResult.ok(terminalService.queryTerminalInfoPage(criteria, page, size));
    }

    /**
     * 新增终端信息
     *
     * @param resources
     * @return
     */
    @Log("终端增加")
    @PostMapping(value = "/add")
    public ResponseResult create(@Validated @RequestBody TerminalInfo resources) {
        return ResponseResult.ok(postTerminalInfoService.create(resources));
    }

    /**
     * 修改终端
     *
     * @param resources
     * @return
     */
    @Log("修改")
    @PutMapping(value = "/update")
    public ResponseResult update(@Validated @RequestBody TerminalInfo resources) {
        postTerminalInfoService.update(resources);
        return ResponseResult.ok();
    }

    /**
     * @param id
     * @return
     */
    @Log("删除终端")
    @DeleteMapping(value = "/delete/{id}")
    public ResponseResult delete(@PathVariable Long id) {
        terminalService.deleteTerminalInfo(id);
        return ResponseResult.ok();
    }
}